package com.eeprint.web.controller.tenant;



import com.eeprint.common.utils.AjaxResult;
import com.eeprint.system.domain.tenant.TenantPrinter;
import com.eeprint.system.domain.tenant.vo.TenantPrinterMessage;
import com.eeprint.system.domain.tenant.vo.TenantWithPageVo;
import com.eeprint.system.domain.tenant.vo.TerminalWithPrinterVo;
import com.eeprint.system.service.tenant.TenantPrinterService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigInteger;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
public class TenantPrinterController {
    @Autowired
    TenantPrinterService tenantPrinterService;

    /**
     * @Author: wsen on 2020/10/17 16:36
     * @Description:显示预打印的设备
     */
    @PostMapping("/tenant/auth/printer/display")
    public AjaxResult displayPrePrinter(@RequestBody() TenantPrinter tenantPrinter){
        List<TerminalWithPrinterVo> tenantPrinters = tenantPrinterService.findPrePrinter(tenantPrinter.getRelTenantId());
        if(tenantPrinters != null){
            return AjaxResult.success(tenantPrinters);
        }
        return AjaxResult.systemError();
    }

    /**
     * @Author: wsen on 2020/10/18 23:28
     * @Description: 查看打印机参数
     */
    @PostMapping("/tenant/auth/printer/getParam")
    public AjaxResult getPrinterParam(@RequestBody() TenantPrinter tenantPrinter){
        tenantPrinter = tenantPrinterService.getPrinterParam(tenantPrinter.getId());
        if(tenantPrinter != null){
            Map<String,Object> map = new HashMap<>();
            map.put("printerPaperSubmit",tenantPrinter.getPrinterPaperSubmit());
            map.put("printerColorSubmit",tenantPrinter.getPrinterColorSubmit());
            map.put("printerDuplexSubmit",tenantPrinter.getPrinterDuplexSubmit());
            return AjaxResult.success(map);
        }
        return AjaxResult.systemError();
    }

    /**
     * @Author: wsen on 2020/10/19 16:12
     * @Description: 查看打印机设备列表
     */
    @PostMapping("/tenant/auth/printer/list")
    public AjaxResult list(@RequestBody TenantWithPageVo tenantWithPageVo){
        PageHelper.startPage(tenantWithPageVo.getPageNum(),tenantWithPageVo.getPageSize());
        List<TenantPrinterMessage> printerMessages = tenantPrinterService.list(tenantWithPageVo.getRelTenantId());
        PageInfo<TenantPrinterMessage> pageInfo = new PageInfo<>(printerMessages);
        return AjaxResult.success(pageInfo);
    }

    /**
     * @Author: wsen on 2020/10/19 16:56
     * @Description: 查看打印设备的详情
     */
    @PostMapping("/tenant/auth/printer/detail")
    public AjaxResult detail(@RequestBody TenantPrinter tenantPrinter){
        TenantPrinter printer = tenantPrinterService.findPrinter(tenantPrinter.getId());
        if(printer != null){
             Map<String,Object> map = new HashMap<>();
             map.put("printerIsUsed",printer.getPrinterIsUsed());
             map.put("printerColorSuport",printer.getPrinterColorSuport());
             map.put("printerPaperSuport",printer.getPrinterPaperSuport());
             map.put("printerDuplexSuport",printer.getPrinterDuplexSuport());
             return AjaxResult.success(map);
        }
        return AjaxResult.systemError("找不到对应的打印机设备");
    }

    /**
     * @Author: wsen on 2020/10/19 17:18
     * @Description: 修改一打印机的设备
     */
    @PostMapping("/tenant/auth/printer/editParam")
    public AjaxResult editParam(@RequestBody TenantPrinter tenantPrinter){
        int result = tenantPrinterService.editParam(tenantPrinter);
        if(result == 1){
            return AjaxResult.success();
        }
        return AjaxResult.systemError("修改失败");
    }

}
